import {reactive} from 'vue'
import {nanoid} from 'nanoid'
let DataList:any=reactive([
    {id:'01',roleCode:'1',roleName:'超级管理员',userId:'1',userName:'1',loginName:'admin',sex:'男',email:'240485@qq.com',phone:'15327437584',wexin:'admin', nailNo:'admin123',status:'1',lockStatus:'1'},
    {id:'02',roleCode:'2',roleName:'普通管理员',email: "2",loginName: "2",nailNo: "2",phone: "2",sex: "2",status:'2',userId: "wPLBUMmhbolp7ltxDrCff",userName: "2",lockStatus:'2',wexin: "2"},
    {id:'03',roleCode:'3',roleName:'超级管理员',email: "2053112503@qq.com",lockStatus: "2",loginName: "3xxx",nailNo: "3gfdnhg",phone: "15437585889",sex: "2",status: "1",userId: "NN2ne8LwSunHkfy5J8-U2",userName: "3",wexin: "3vbtm"}
])
const getList=()=>{
    return DataList
}
const add=async (record:any)=>{
    return new Promise((resolve,reject)=>{
        DataList.push({...record,userId:nanoid(),id:nanoid()})
        console.log(DataList, 'add');        
        resolve('success')
    })
   
}
const changLock=(record:any)=>{//锁定
        DataList.forEach((item:any,i:string)=>{
            if(item.id===record.id){
                DataList[i].lockStatus='1'
            }
        })
}
const changeStatus=(record:any)=>{
     DataList.forEach((item:any)=>{
         if(item.id===record.id){              
             item.status=item.status=='1'? item.status='2':item.status='1'
         }
     })
     console.log(DataList,'状态');
}
const remove=(record:any)=>{
    DataList.forEach((e:any,i:string|number)=> {
        if(e.id===record.id ){
            console.log('///');
            DataList.splice(i,1)
            return  
        } 
    });
    console.log(DataList,'remove');
} 
const changList=(record:any)=>{//编辑
    DataList.forEach((item:any,i:string)=>{
        if(item.id===record.id){       
          DataList[i]={...record,...item}
        }
    })
    console.log(DataList,'编辑');
}
export {
    getList,
    changLock,
    remove,
    add,
    changList,
    changeStatus
}